


window.onload = function () {


    document.getElementById('btn').onclick = function () {
        let unameValue = document.getElementById('uname').value;

        let upsValue = document.getElementById('upaswd').value;
        let xhr = new XMLHttpRequest();
        xhr.open('POST', '/user/login', true)
        xhr.responseType = 'json'
        xhr.setRequestHeader('Content-Type', 'Application/x-www-form-urlencoded')
        xhr.send(`uname=${unameValue}&upassword=${upsValue}`)

        xhr.onreadystatechange = function () {
            if (xhr.readyState == 4 && xhr.status == 200) {

                if (xhr.response.code == 200) {
                    // alert(xhr.response.msg)

                    location.href = '/admin/showadmin';
                } else {
                    alert(xhr.response.msg)
                    document.getElementById('uname').value = '';
                    document.getElementById('upaswd').value = ''
                }
            }
        }
    }
}